package tool

import (
	"github.com/hajimehoshi/ebiten/v2"
	"github.com/hajimehoshi/ebiten/v2/ebitenutil"
	"parkour/model"
)

type Bullet struct {
	image *ebiten.Image
	//width       int
	//height      int
	//X           float64
	//y           float64
	SpeedFactor float64
	*model.Entity
	//*Object
}

func (bullet *Bullet) NewBullet(cfg *model.Config, figure *model.Figure) *Bullet {
	img, _, err := ebitenutil.NewImageFromFile("static/img/bullet.png")
	if err != nil {
		panic(err)
	}
	return &Bullet{
		image: img,
		//width:       cfg.BulletWidth,
		//height:      cfg.BulletHeight,
		//X:           figure.X + float64(figure.Width-cfg.BulletWidth),
		//y:           figure.Y + float64(figure.Height/2),
		SpeedFactor: cfg.BulletSpeedFactor,
		Entity: &model.Entity{
			Width:  cfg.BulletWidth,
			Height: cfg.BulletHeight,
			X:      figure.X + float64(figure.Width-cfg.BulletWidth),
			Y:      figure.Y + float64(figure.Height/2),
		},
		//Object: &Object{
		//	X:      0,
		//	Y:      0,
		//	Width:  cfg.BulletWidth,
		//	Height: cfg.BulletHeight,
		//},
	}
}
func (bullet *Bullet) Draw(screen *ebiten.Image) {
	op := &ebiten.DrawImageOptions{}
	op.GeoM.Translate(bullet.X, bullet.Y)
	screen.DrawImage(bullet.image, op)
}

func (bullet *Bullet) OutOfScreen(cfg *model.Config) bool {
	return bullet.X > float64(cfg.ScreenWidth)
}
